#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include "RBTree.h"

//map
//key value
namespace xg
{
	template<class k, class T>
	class map
	{
	public:
		struct MapkOfT
		{
			const k& operator()(const pair<k,T>& data)
			{
				return data.first;
			}
		};
		typedef typename RBTree<k, pair<const k, T>, MapkOfT>::Iterator iterator;
		typedef typename RBTree<k, pair<const k, T>, MapkOfT>::ConstIterator const_iterator;
		pair<iterator,bool> Insert(const pair<k,T>& data)
		{
			return _t.Insert(data);
		}
		iterator begin()
		{
			return _t.Begin();
		}
		iterator end()
		{
			return _t.End();
		}
		const_iterator begin() const
		{
			return _t.begin();
		}
		const_iterator end() const
		{
			return _t.End();
		}
		T& operator[](const k& key)
		{
			pair<iterator, bool> ret = Insert({ key, T()});
			return ret.first->second;
		}

	private:
		RBTree<k, pair<const k,T>, MapkOfT> _t;
	};
}